package com.uenpay.oem.ui.reserver;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.uenpay.im.utilities.Toasts;
import com.uenpay.im.weight.dialog.LoadDialog;
import com.uenpay.oem.R;
import com.uenpay.oem.common.AppConstant;
import com.uenpay.res.widget.dialog.WhiteBgDialog;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.util.app.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by PS on 2017/6/19.
 */
public class ReservedcodeActivity extends BaseActivity implements AddnewcardContract.View {

    ReservedcodePresenter mPresenter;
    private Intent intent;
    @BindView(R.id.hind_cord)
    TextView tvBank;
    @BindView(R.id.et_type)
    TextView tvType;
    @BindView(R.id.year)
    EditText etMonthYear;
    @BindView(R.id.et_cvv)
    EditText etCvv;
    @BindView(R.id.phone_code)
    EditText etPhone;

    private String cardType;
    private BankCardInfo info;
    private String bankName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        intent = getIntent();
        initData();
        setTitle("预留手机号");
        setPresenter(null);
        findViewById(R.id.next_step).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phone = etPhone.getText().toString().trim();
                String time = etMonthYear.getText().toString().trim();
                String cvv = etCvv.getText().toString().trim();
                if( mPresenter.checkData(phone,time,cvv)){
                    info.setPhone(phone);
                    info.setExpireDate(time);
                    info.setCvvCode(cvv);
                    mPresenter.addCard(info);
                }

            }
        });

    }

    private void initData() {
        info = intent.getParcelableExtra("bankInfo");
        bankName = info.getBankName();
        cardType = info.getCardType();

        tvBank.setText(bankName);
        tvType.setText("信用卡");
    }
    public BankCardInfo getInfo(){
        return info;
    }

    public void goSuccessActivity() {
        Intent intent = new Intent(ReservedcodeActivity.this, AddBankSucceedActivity.class);
        startActivityForResult(intent, AppConstant.ADD_BANK_REQUEST_CODE);
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_reservedcode;
    }

    @Override
    public void initView(View view) {

    }

    @Override
    public void setPresenter(Object presenter) {
        mPresenter = new ReservedcodePresenter(this);
    }

    @Override
    public void showToast(String msg) {
        Toasts.shortToast(this, msg);
    }

    @Override
    public void showLoading() {
        LoadDialog.show(this);
    }

    @Override
    public void dismissLoading() {
        LoadDialog.dismiss(this);
    }

    @Override
    public void setData(BankCardInfo info) {

    }

    @OnClick(R.id.iv_info)
    public void clickInfo() {
        final WhiteBgDialog phoneDialog = new WhiteBgDialog(this, R.layout.dialog_show_phone_info);
        phoneDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                phoneDialog.dissmiss();
            }
        });
    }

    @OnClick(R.id.iv_expire_info)
    public void clickExpireInfo() {
        final WhiteBgDialog expireDialog = new WhiteBgDialog(this, R.layout.dialog_show_expire_info);
        expireDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                expireDialog.dissmiss();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //添加成功，finish
        if (requestCode == AppConstant.ADD_BANK_REQUEST_CODE && resultCode == RESULT_OK) {
            setResult(RESULT_OK);
            finish();
        }
    }
}
